package com.yt.ds.chapter4;

/**
 * @Author: lzf
 * @Date: 2020/7/31 16:44
 * @Description: 加权边API
 */
public class DirectedEdge implements Comparable<DirectedEdge>,IEdge {
    private final int from;    // 顶点1
    private final int to;    // 顶点2
    private final double weight;    // 边的权重

    public DirectedEdge(int v, int w, double weight) {
        this.from = v;
        this.to = w;
        this.weight = weight;
    }

    public double getWeight() {
        return weight;
    }

    public int from() {
        return from;
    }

    // 另一个顶点
    public int to() {
        return to;
    }

    @Override
    public int compareTo(DirectedEdge o) {
        return Double.compare(this.weight, o.getWeight());
    }

    @Override
    public String toString() {
        return String.format("%d-%d %.2f", from, to, weight);
    }
}
